import { defineStore } from 'pinia'
import { ref, computed } from "vue"
export const useAppStore = defineStore(
    'app',
    () => {
        let count = ref(0)

        const setCount = (num) => {
            count.value = count.value + num
        }

        const windowInfo = ref({})
        const setWindowInfo = (info) => {
            windowInfo.value = info
        }

        const statusBarHeight = computed(() => windowInfo.value.statusBarHeight || 0)
        const safeAreaTop = computed(() => windowInfo.value.safeAreaInsets?.top || 0)
        const safeAreaBottom = computed(() => windowInfo.value.safeAreaInsets?.bottom || 0)

        return {
            count,
            setCount,
            windowInfo,
            setWindowInfo,
            statusBarHeight,
            safeAreaTop,
            safeAreaBottom,
        }
    },
    // TODO: 持久化
    {
        // 网页端的配置
        // persist: true,
        // 小程序端的配置
        persist: {
            storage: {
                getItem: (key) => uni.getStorageSync(key),
                setItem: (key, value) => uni.setStorageSync(key, value)
            },
        },
    },
)